package com.ljs.vuetest.controller;

import com.ljs.vuetest.bean.Student;
import com.ljs.vuetest.config.TokenUtils;
import com.ljs.vuetest.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
public class LoginHanddler {
    @Resource
    StudentService studentService;
    @RequestMapping("/tologin")
    public  String tologin(){
        return "login";//去登陆
    }

    //发送token
    @ResponseBody
    @RequestMapping("/login")
        public String login(@RequestParam("name") String name,@RequestParam("password") String password){
        Student student=null;
        student=  studentService.login(name,password);
        System.out.println(student);
        String token="";
        if(student!=null){
            token= TokenUtils.token(name,password);
        }
        return  token;
        }
        @RequestMapping("/cheaktoken")
        @ResponseBody
    public String cheaktoken(@RequestParam("token") String token){
        String msg="";
        boolean flag=false;
            flag=    TokenUtils.verify(token);
            if(flag){
                msg="登录成功";

            }else{
                msg="登录失败";
            }
         return msg;

        }


}
